//
//  WmcTeamMemberModel.swift
//  YPWatermarkCamera
//
//  Created by yupao_ios_macmini06 on 2022/9/21.
//

import Foundation
import YPNetwork

/*
 avatar = "";
 memberId = 642;
 mobile = "";
 name = "\U5148\U751f";
 registered = 1;
 remark = "\U5148\U751f";
 role = 1;
 status = 1;
 tenantId = 6018;
 uid = 20097914
 */

class WmcTeamMemberModel: YPNetworkJsonProtocol, WmcteamMemberModelProtocol {
    enum UserRole: Int, HandyJSONEnum {
        case manager = 0
        case member = 1
    }

    required init() {}

    var avatar: String?
    var memberId: Int?
    var mobile: String?
    var name: String?
    var registered: Bool?
    var remark: String?
    /// 权限   角色：0-管理员，1-成员
    var role: UserRole?
    /// 是否激活
    var status: Bool?
    var tenantId: Int?
    var uid: Int = 0

    /// 额外增加字段，便于页面传值
    var teamId: Int?

    var showName: String {
        var tempName = ""
        if remark != nil {
            tempName = remark ?? ""
        } else {
            tempName = name ?? ""
        }
        tempName = tempName + (isSelf() ? "(我)" : "")
        return tempName
    }

    /// 改种方式
    var showNamex: String {
        var tempName = ""
        if remark != nil {
            tempName = remark ?? ""
        } else {
            tempName = name ?? ""
        }
        return tempName
    }

    /// 权限tag类型
    var tagType: WmcTeamMemberTagType {
        guard let registered = registered, let role = role else {
            return .inactivated
        }
        if registered {
            if role == .member {
                return .member
            } else if role == .manager {
                return .manager
            } else {
                return .inactivated
            }
        } else {
            return .inactivated
        }
    }

    /// 判断是否为自己
    func isSelf() -> Bool {
        return (WmcLoginManager.shared.wmcAccountModel?.yupaoId ?? 0) == (uid )
    }

    var yupaoId: Int {
        return (WmcLoginManager.shared.wmcAccountModel?.yupaoId ?? 0)
    }
}
